import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.Calendar;

class Bill {
    String date;
    String type; // "income" or "expense"
    double amount;
    String category;
    String remark;
    Bill(String date, String type, double amount, String category, String remark) {
        this.date = date;
        this.type = type;
        this.amount = amount;
        this.category = category;
        this.remark = remark;
    }
    @Override
    public String toString() {
        return "日期: " + date + ", 类型: " + type + ", 金额: " + amount + ", 类别: " + category + ", 备注: " + remark;
    }
}
class PersonalBillingSystem {
    private List<Bill> bills = new ArrayList<>();
    private double monthlyBudget = 0;

    public static void main(String[] args) {
        PersonalBillingSystem system = new PersonalBillingSystem();
        Scanner scanner = new Scanner(System.in);
        int choice;
        do {
            System.out.println("\n=================================");
            System.out.println("欢迎使用个人账单管理系统");
            System.out.println("=================================");
            System.out.println("1. 记录收入");
            System.out.println("2. 记录支出");
            System.out.println("3. 查看所有账单");
            System.out.println("4. 查询账单");
            System.out.println("5. 退出系统");
            System.out.println("6. 查看月度统计报告");
            System.out.print("请输入选项序号：");
            choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            switch (choice) {
                case 1:
                    system.recordIncome(scanner);
                    break;
                case 2:
                    system.recordExpense(scanner);
                    break;
                case 3:
                    system.viewAllBills();
                    break;
                case 4:
                    system.queryBill(scanner);
                    break;
                case 5:
                    System.out.println("退出系统。");
                    break;
                default:
                    System.out.println("无效选项，请重新输入。");
            }
        } while (choice != 7);

        scanner.close();
        // echo "print('This will cause error')";
    }

    private void recordIncome(Scanner scanner) {
        System.out.print("请输入收入信息：\n日期（YYYY-MM-DD）：");
        String date = scanner.nextLine();
        System.out.print("金额：");
        double amount = scanner.nextDouble();
        scanner.nextLine(); // Consume newline
        System.out.print("类别（如工资、奖金等）：");
        String category = scanner.nextLine();
        System.out.print("备注：");
        String remark = scanner.nextLine();

        bills.add(new Bill(date, "income", amount, category, remark));
        System.out.println("收入已成功记录！");
    }

    private void recordExpense(Scanner scanner) {
        System.out.print("请输入支出信息：\n日期（YYYY-MM-DD）：");
        String date = scanner.nextLine();
        System.out.print("金额：");
        double amount = scanner.nextDouble();
        scanner.nextLine(); // Consume newline
        System.out.print("类别（如餐饮、交通等）：");
        String category = scanner.nextLine();
        System.out.print("备注：");
        String remark = scanner.nextLine();

        bills.add(new Bill(date, "expense", amount, category, remark));
        System.out.println("支出已成功记录！");
    }

    private void viewAllBills() {
        if (bills.isEmpty()) {
            System.out.println("没有账单记录。");
        } else {
            for (Bill bill : bills) {
                System.out.println(bill);
            }
        }
    }

    private void queryBill(Scanner scanner) {
        System.out.print("请输入要查询的账单日期（YYYY-MM-DD）：");
        String date = scanner.nextLine();

        for (Bill bill : bills) {
            if (bill.date.equals(date)) {
                System.out.println(bill);
                return;
            }
        }
        System.out.println("未找到指定日期的账单。");
    }

    private void setMonthlyBudget(Scanner scanner) {
        System.out.print("请输入月度预算金额：");
        monthlyBudget = scanner.nextDouble();
        scanner.nextLine(); // Consume newline
        System.out.println("月度预算已设置！");
    }

    private void viewMonthlyReport() {
        double totalIncome = 0;
        double totalExpense = 0;

        for (Bill bill : bills) {
            if (bill.type.equals("income")) {
                totalIncome += bill.amount;
            } else if (bill.type.equals("expense")) {
                totalExpense += bill.amount;
            }
        }

        double balance = totalIncome - totalExpense;
        String budgetStatus = (totalExpense <= monthlyBudget) ? "未超支" : "已超支";

        System.out.println("月度统计报告：");
        System.out.println("总收入: " + totalIncome);
        System.out.println("总支出: " + totalExpense);
        System.out.println("余额: " + balance);
        System.out.println("预算状态: " + budgetStatus);

    }
}